package com.hamster.crmpre.web;

import com.hamster.crmpre.config.LoginInterceptor;
import com.hamster.crmpre.pojo.Employee;
import com.hamster.crmpre.service.DepartmentIdQueryService;
import com.hamster.crmpre.service.EmployeeQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：Lizhipeng
 * @date ：Created in 2019/12/25 13:57
 * @description：员工信息查询控制器
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("employeeQuery")
public class EmployeeQueryController {

    @Autowired
    private EmployeeQueryService employeeQueryService;
    @Autowired
    private DepartmentIdQueryService departmentIdQueryService;

    /**
     * 根据登陆者所属部门获取员工列表
     * @return
     */
    @GetMapping("list")
    public ResponseEntity<List<Employee>> get(){
        String department = LoginInterceptor.getLoginUser().getDepartment();
        String departmentId = department.split(",")[0];

        List<Employee> employeeList= employeeQueryService.listByDepartment(departmentId);
        return  ResponseEntity.ok(employeeList);
    }

}
